import ref from 'ref'
import ffi from 'ffi'
import StructType from 'ref-struct'
import FaceBase from './FaceBase'

// 引擎版本信息
let AFR_FSDK_Version = StructType({
  lCodebase: FaceBase.MInt32,
  lMajor: FaceBase.MInt32,
  lMinor: FaceBase.MInt32,
  lBuild: FaceBase.MInt32,
  lFeatureLevel: FaceBase.MInt32,
  Version: FaceBase.MPChar,
  BuildDate: FaceBase.MPChar,
  CopyRight: FaceBase.MPChar
})

// 已检测到的脸部信息
let AFR_FSDK_FACERES = StructType({
  rcFace: FaceBase.MRECT,
  lOrient: FaceBase.MInt32
})

// 脸部特征信息
let AFR_FSDK_FACEMODEL = StructType({
  pbFeature: FaceBase.MHandleType,
  lFeatureSize: FaceBase.MInt32
})

let libname = './libs/libarcsoft_fsdk_face_recognition.dll'
let Library = ffi.Library(libname, {
  'AFR_FSDK_GetVersion': [ref.refType(AFR_FSDK_Version), [FaceBase.MHandleType]],
  'AFR_FSDK_InitialEngine': [FaceBase.MLong, [FaceBase.MPChar, FaceBase.MPChar, FaceBase.MHandleType, FaceBase.MInt32, FaceBase.MHandleRefType]],
  'AFR_FSDK_UninitialEngine': [FaceBase.MLong, [FaceBase.MHandleType]],
  'AFR_FSDK_ExtractFRFeature': [FaceBase.MLong, [FaceBase.MHandleType, ref.refType(FaceBase.ASVLOFFSCREEN), ref.refType(AFR_FSDK_FACERES), ref.refType(AFR_FSDK_FACEMODEL)]],
  'AFR_FSDK_FacePairMatching': [FaceBase.MLong, [FaceBase.MHandleType, ref.refType(AFR_FSDK_FACEMODEL), ref.refType(AFR_FSDK_FACEMODEL), ref.refType(ref.types.float)]]
})

exports.AFR_FSDK_Version = AFR_FSDK_Version
exports.AFR_FSDK_FACERES = AFR_FSDK_FACERES
exports.AFR_FSDK_FACEMODEL = AFR_FSDK_FACEMODEL
exports.AFR_FSDK_GetVersion = Library.AFR_FSDK_GetVersion
exports.AFR_FSDK_InitialEngine = Library.AFR_FSDK_InitialEngine
exports.AFR_FSDK_UninitialEngine = Library.AFR_FSDK_UninitialEngine
exports.AFR_FSDK_ExtractFRFeature = Library.AFR_FSDK_ExtractFRFeature
exports.AFR_FSDK_FacePairMatching = Library.AFR_FSDK_FacePairMatching
